<?php

namespace App\Jobs;

use App\Datalog\Events\FirstupEventLog;
use App\Models\Firstups;
use App\Services\AdMatchMonitorService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class FirstupQueue implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    use TraitQueue;

    protected $firstupId;
    protected $params;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($id, $params)
    {
        $this->firstupId = $id;
        $this->params = $params;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $firstup = Firstups::find($this->firstupId);

        // 数据落地
        FirstupEventLog::getInstance()->addLog($firstup);

        // 进行一次激活匹配买量点击监控
        AdMatchMonitorService::getInstance()->matchMonitor($firstup);
    }
}
